<template>
	<view @click="selectMediaClick">
		<slot name="content"></slot>
	</view>
</template>

<script>
	export default {
		props: {
			uploadType: {
				type: String,
				default: 'image'
			},
			mediaType: {
				type: Array,
				default: ['image']
			},
			count: {
				type: Number,
				default: 1
			}
		},
		data() {
			return {
				
			}
		},
		methods: {
			//选择图片
			selectMediaClick(){
				// #ifdef MP
				uni.chooseMedia({
					count: this.count,
					mediaType: this.mediaType,
					sourceType: ['camera', 'album'],
				}).then((res) => {
					if (res && res.tempFiles && res.tempFiles.length > 0) {
						let path = res.tempFiles[0].tempFilePath
						this.$emit('selectBack', {data: path})
					}
				})
				// #endif
				// #ifdef H5 || APP-PLUS
				if(this.uploadType == 'video'){
					uni.chooseVideo({
						sourceType: ['album'], //从相册选择、拍照
						success: ((res) => {
							console.log(res);
							if (res && res.tempFilePath) {
								let path = res.tempFilePath
								this.$emit('selectBack', {data: path})
							}
						})
					});
				}else{
					uni.chooseImage({
						count: this.count, //默认9
						sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: ['album'], //从相册选择、拍照
						success: ((res) => {
							if (res && res.tempFilePaths && res.tempFilePaths.length > 0) {
								let path = res.tempFilePaths[0]
								this.$emit('selectBack', {data: path})
							}
						})
					});
				}
				// #endif
			}
		}
	}
</script>

<style scoped>

</style>
